package com.ruibang.glass.produce.controller.pl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruibang.glass.produce.constant.Constants;
import com.ruibang.glass.produce.domain.req.BucketShipmentRecordReq;
import com.ruibang.glass.produce.entity.BucketShipmentRecord;
import com.ruibang.glass.produce.service.BucketShipmentRecordService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @Author: songJinKang
 * @CreateTime: 2024-03-11  10:34
 * @Description: TODO
 * @Version: 1.0
 */

@Api(tags = "生产-配料-料罐装货记录控制器")
@RestController
@RequestMapping("/api/glass/produce/pl/bucketShipmentRecord")
public class BucketShipmentRecordController {

    @Autowired
    private BucketShipmentRecordService bucketShipmentRecordService;

    @PostMapping("/pageQuery")
    @ApiOperation(value = "查询记录", response = ResultBody.class)
    public ResultBody<IPage<BucketShipmentRecord>> pageQuery(@RequestBody BucketShipmentRecordReq bucketShipmentRecordReq) {
        return ResultBody.success(bucketShipmentRecordService.pageQuery(bucketShipmentRecordReq));
    }

    @GetMapping("/getById/{id}")
    @ApiOperation(value = "根据ID获取详情", response = ResultBody.class)
    public ResultBody getById(@PathVariable String id) {
        return ResultBody.success(bucketShipmentRecordService.getById(id));
    }

    @PostMapping("/save")
    @ApiOperation(value = "新增", response = ResultBody.class)
    public ResultBody save(@RequestBody BucketShipmentRecord bucketShipmentRecord) {
        bucketShipmentRecord.setIsDelete(Constants.ZERO_STR);
        bucketShipmentRecordService.save(bucketShipmentRecord);
        return ResultBody.success(bucketShipmentRecord.getId());
    }

    @PutMapping("/edit")
    @ApiOperation(value = "编辑", response = ResultBody.class)
    public ResultBody edit(@RequestBody BucketShipmentRecord bucketShipmentRecord) {
        bucketShipmentRecordService.edit(bucketShipmentRecord);
        return ResultBody.success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除", response = ResultBody.class)
    public ResultBody delete(@PathVariable String id) {
        bucketShipmentRecordService.deleteById(id);
        return ResultBody.success();
    }

    @PostMapping("/export")
    @ApiOperation(value = "数据导出")
    public void export(@RequestBody BucketShipmentRecordReq bucketShipmentRecordReq, HttpServletResponse response) {
        bucketShipmentRecordService.export(bucketShipmentRecordReq, response);
    }
}
